package view.render.weapon
{
	import enums.ColorLib;
	import enums.main.UISize;
	
	import feathers.controls.Label;
	
	import model.vo.weapon.FluteStaffVo;
	
	import starling.text.TextField;
	import starling.utils.Color;
	
	import util.WeaponUtil;
	
	import view.render.BaseScrollerItem;
	
	
	/**
	 * 狩猎笛旋律item
	 * @author £iang
	 * 
	 */	
	public class FluteStaffItem extends BaseScrollerItem
	{
		//-----------------------------
		// variables
		//-----------------------------
		
		/** 旋律 */
		public var melodyLabel:Label;
		/** 吹奏效果 */
		public var effectLabel:TextField;
		/** 再次吹奏 */
		public var reEffectLabel:TextField;
		/** 持续时间 */
		public var timeLabel:Label;
		/** 延续时间 */
		public var reTimeLabel:Label;
		/** 备注 */
		public var psLabel:TextField;
		
		//-----------------------------
		// properties
		//-----------------------------
		
		//-----------------------------
		// setter&getter
		//-----------------------------
		
		//-----------------------------
		// methods
		//-----------------------------
		
		/**
		 * 初始化函数 
		 * 
		 */		
		override protected function initializeOther():void
		{
			super.initializeOther();
			melodyLabel = new Label();
			melodyLabel.textRendererProperties.isHTML = true;
			this.addChild( melodyLabel );
			
			effectLabel = new TextField(
				UISize.MAIN_W * 0.4, 
				_itemH * UISize.DPI_SCALE,
				"", "微软雅黑,宋体", 24 * UISize.DPI_SCALE, Color.WHITE
			);
			effectLabel.vAlign = "center";
			effectLabel.hAlign = "left";
			scollerContainer.addChild( effectLabel );
			
			reEffectLabel = new TextField(
				UISize.MAIN_W * 0.4, 
				_itemH * UISize.DPI_SCALE,
				"", "微软雅黑,宋体", 24 * UISize.DPI_SCALE, ColorLib.GOLDEN
			);
			reEffectLabel.vAlign = "center";
			reEffectLabel.hAlign = "left";
			scollerContainer.addChild( reEffectLabel );
			
			timeLabel = new Label();
			scollerContainer.addChild( timeLabel );
			
			reTimeLabel = new Label();
			scollerContainer.addChild( reTimeLabel );
			
			psLabel = new TextField(
				UISize.MAIN_W * 0.7, 
				_itemH * UISize.DPI_SCALE,
				"", "微软雅黑,宋体", 24 * UISize.DPI_SCALE, Color.WHITE
			);
			psLabel.vAlign = "center";
			psLabel.hAlign = "left";
			scollerContainer.addChild( psLabel );
		}
		
		/**
		 * 调整组件 
		 * 
		 */		
		override protected function draw():void
		{
			var labelY:Number = ( _itemH - 
				43 ) / 2 * UISize.DPI_SCALE;
			var padding:Number = UISize.TITLE_PADDING_LEFT * UISize.DPI_SCALE;
			var firstLabelFullW:Number;
			
			melodyLabel.x = padding;
			melodyLabel.y = labelY;
			firstLabelFullW = UISize.MAIN_W * _firstPercent;
			
			effectLabel.x = 0;
			effectLabel.width = UISize.MAIN_W * 0.4;
			
			timeLabel.y = labelY;
			timeLabel.x = UISize.MAIN_W * 0.4;
			timeLabel.width  = UISize.MAIN_W * 0.3;
			
			reEffectLabel.x = UISize.MAIN_W * 0.7;
			reEffectLabel.width = UISize.MAIN_W * 0.4;
			
			reTimeLabel.y = labelY;
			reTimeLabel.x = UISize.MAIN_W * 1.1;
			reTimeLabel.width  = UISize.MAIN_W * 0.3;
			
			psLabel.x = UISize.MAIN_W * 1.4;
			psLabel.width = UISize.MAIN_W * 0.7;
			
			scollerContainer.x = firstLabelFullW;
			scollerContainer.height = _itemH * UISize.DPI_SCALE;
			scollerContainer.width = UISize.MAIN_W - firstLabelFullW;
			
			this.width = UISize.MAIN_W;
			this.height = _itemH * UISize.DPI_SCALE;
		}
		
		/**
		 * 设置item数据 
		 * @param data 数据
		 * 
		 */		
		public function setData( data:FluteStaffVo ):void
		{
			melodyLabel.text = WeaponUtil.getMelodyText( data.melody );
			effectLabel.text = data.effect;
			timeLabel.text = data.time;
			reEffectLabel.text = data.reEffect;
			reTimeLabel.text = data.reTime;
			psLabel.text = data.ps;
		}
		
		//-----------------------------
		// events
		//-----------------------------
		
		//-----------------------------
		// dispose
		//-----------------------------
		
		/**
		 * 析构滚动条容器中的标签 
		 * 
		 */		
		protected override function disposeAnythingInContainer():void
		{
			disposeLabels( [
				"melody", "effect",
				"reEffect", "time",
				"reTime", "ps"
			] );
		}
		
		//-----------------------------
		// construction
		//-----------------------------
		
		/**
		 * 构造函数
		 *
		 */
		public function FluteStaffItem()
		{
			super();
			_itemH = UISize.FLUTE_STAFF_ITEM_H;
			_firstPercent = 0.3;
			initialize();
		}
	}
}